package ystp.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ystp.dao.XinguotanMapper;
import ystp.model.Xinguotan;
import ystp.model.XinguotanExample;
import ystp.model.Xinguotanjieguo;

import java.util.List;
import java.util.Map;

@Service
public class XinguotanService {

    @Autowired
    XinguotanMapper ddMapper;

    public boolean add (Xinguotan ppXinguotan){
        return ddMapper.insert(ppXinguotan)==1;
    }

    public boolean isExistByXiangmuId(String ppXiangmuId){
        XinguotanExample mmExample = new XinguotanExample();
        mmExample.createCriteria().andXiangmuidEqualTo(ppXiangmuId);
        return ddMapper.selectByExample(mmExample).size()>0;
    }

    public Integer getXinguotanCount(String ppXiangmuId) {
        Object mmCount = ddMapper.countXinguotanByXiangmuId(ppXiangmuId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public List<Map<String, Object>> findXinguotanPagingByXiangmuId(String ppxiangmuId, int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findXinguotanPagingByXiangmuId(ppxiangmuId,mmStartIndex,ppPageSize);
    }

    public Integer countXinguotanByXiangmuId(String ppXiangmuId) {
        Object mmCount = ddMapper.countXinguotanByXiangmuId(ppXiangmuId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public List<Map<String, Object>> findXinguotanBiaojueByXiangmuId(String ppxiangmuId,String ppUserId,String ppyaopinmingcheng,String ppzhuankefenzu,String ppshenqingkeshi,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findXinguotanBiaojueByXiangmuId(ppxiangmuId,ppUserId,ppyaopinmingcheng,ppzhuankefenzu,ppshenqingkeshi,mmStartIndex,ppPageSize);
    }

    public Integer countXinguotanBiaojueByXiangmuId(String ppXiangmuId,String ppUserId,String ppyaopinmingcheng,String ppzhuankefenzu,String ppshenqingkeshi) {
        Object mmCount = ddMapper.countXinguotanBiaojueByXiangmuId(ppXiangmuId,ppUserId,ppyaopinmingcheng,ppzhuankefenzu,ppshenqingkeshi);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }


    public boolean deleteByXiangmuId(String ppXiangmuId){
        XinguotanExample mmExample = new XinguotanExample();
        mmExample.createCriteria().andXiangmuidEqualTo(ppXiangmuId);
        return ddMapper.deleteByExample(mmExample)>=0;
    }

    public Xinguotan findOne(String id){
        return ddMapper.selectByPrimaryKey(id);
    }

    public List<Map<String,Object>> findZhuankefenzuByXiangmuid(String ppXiangmuId){
        return ddMapper.findZhuankefenzuByXiangmuid(ppXiangmuId);
    }

    public List<Map<String,Object>> findShenqingkeshiByXiangmuid(String ppXiangmuId){
        return ddMapper.findShenqingkeshiByXiangmuid(ppXiangmuId);
    }


}
